package com.wwg.reflect.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class MyInvocationHandler implements InvocationHandler {

    private BeStronger strongBefore;
    private BeStronger strongAfter;

    private Object obj;

    public MyInvocationHandler(Object obj,BeStronger strongBefore,BeStronger strongAfter) {
        this.obj = obj;
        this.strongBefore = strongBefore;
        this.strongAfter = strongAfter;
    }

    /**
     * @Description: 代理方法执行
     * @Param: [proxy, method, args]
     * @return: java.lang.Object
     * @Author: wwg
     * @Date: 2021/7/26
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("代理前");
        if (strongBefore != null) {
            strongBefore.beStrong();
        }
//        method.invoke(proxy, args);
        method.invoke(obj, args);
        System.out.println("代理后");
        if (strongAfter != null) {
            strongAfter.beStrong();
        }

        return null;
    }
}
